//
//  CLLNavigationController.swift
//  CLWeiNo
//
//  Created by DDC on 2017/10/10.
//  Copyright © 2017年 DDC. All rights reserved.
//

import UIKit

class CLLNavigationController: UINavigationController {
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }

    /// 重写push方法
    ///
    /// - Parameters:
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        // 如果不是栈底控制器,不需要隐藏底部tabbar
        if childViewControllers.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            // 设置返回按钮的显示
            if let vc = viewController as? CLLBaseViewController {
                
                // 设置自定义按钮
                let button  = UIButton.hm_button(withTitle: "返回", fontSize: 16, textColor: UIColor.gray, higlightTextColor: UIColor.orange)
                let image = UIImage(named: "new_feature_share_true")
                button.setImage(image, for: [])
                button.sizeToFit()
                button.addTarget(self, action: #selector(popToParent), for: .touchUpInside)
                vc.navItem.leftBarButtonItem = UIBarButtonItem(customView: button)
                
            }
            
        }
        super.pushViewController(viewController, animated: true)

    }
    
    /// 返回到上一层
    @objc func popToParent() {
        popViewController(animated: true)
    }
}
